package models;

import java.util.*;

import javax.persistence.*;

import play.data.validation.Constraints.Required;
import play.db.ebean.Model;

@Entity
public class Type extends Model {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	public Long id;

	@Required
	@Column(unique=true)
	public String nType;

	public String categorie;
	
//	@OneToMany//(mappedBy="nType")
//	List<Produit> prods;

	public static Finder<Long,Type> find = new Finder<Long, Type>(
			Long.class, Type.class
			);

	public static Finder<Long,Type> findNom = new Finder<Long, Type>(
			Long.class, Type.class
			);
	public static List<Type> all() {
		return find.all();
	}
	
	public static Map<String,String> options() {
        LinkedHashMap<String,String> options = new LinkedHashMap<String,String>();
        for(Type c: Type.find.orderBy("nType").findList()) {
            options.put(c.id.toString(), c.nType);
        }
        return options;
    }

	public static void create(Type _type) {
		_type.save();
	}

	public static void delete(Long id) {
		find.ref(id).delete();
	}
	

	public static String findType(Long id){
		return Type.find.ref(id).nType;
	}
}
